{extend name='public/base'}
{block name='content'}
<!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        {$item['item1']}
        <small>{$item['item2']}</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> {$item['item1']}</a></li>
        <li class="active">{$item['item2']}</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="row" >
        <div class="col-xs-12">
          <!-- /.box -->
          <div class="box">
            <div class="box-header">
              <h3 class="box-title">列表</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
                <table class="layui-hide"  id='test' lay-filter="test"></table>
                <script type="text/html" id="toolbarDemo">
                    <div class="layui-btn-container">
                        <button class="layui-btn layui-btn-sm" lay-event="addBanner">新增轮播图</button>
                        <button class="layui-btn layui-btn-sm" lay-event="batchHandler">批量删除</button>
                    </div>
                </script>
                <script type="text/html" id="indexTpl">
                    {{d.LAY_TABLE_INDEX+1}}
                </script>
                <script type="text/html" id="bannerImg">
                    <img src="__UP__/{{d.banner}}">
                </script>
                <script type="text/html" id="bannerStatus">
                    {{ d.status == 1 ? '启用' : '禁用' }}
                </script>
                <script type="text/html" id="bannerFlg">
                    {{# if (d.flg=== 1) { }}
                         <span>首页</span>
                    {{# } else if(d.flg=== 2) { }}
                        <span>入口</span>
                    {{# } else { }}
                        <span>其他</span>
                    {{# } }}
                </script>
                <script type="text/html" id="barDemo">
                    <a class="layui-btn layui-btn-xs" onclick="lotus_show('编辑轮播图','edit_banner.html?id={{d.id}}',500,550)">编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="w_tableDel('{{d.id}}', 'deleteRow')">删除</a>
                </script>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
{/block}


{block name='script'}
<script>
  //增加表格数据
  $(function (){
      layui.use('table', function() {
          var table = layui.table
          cols = [
                      {type: 'checkbox'}
                      ,{title: '序号',templet: '#indexTpl',width: '5%'}
                      ,{field:'banner', title:'图片', toolbar: '#bannerImg'}
                      ,{field:'describe', title:'描述'}
                      ,{field:'status', title:'状态', toolbar: '#bannerStatus'}
                      ,{field:'flg', title:'位置', toolbar: '#bannerFlg'}
                      ,{field:'datetime', title:'更新时间',  sort: true}
                      ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
                  ]
          w_layuiTable('#test','get_table_data',cols,'#toolbarDemo')

          table.on('toolbar(test)', function(obj){
              var checkStatus = table.checkStatus(obj.config.id);
              switch(obj.event){
                  case 'addBanner':
                      lotus_show('新增轮播图','add_banner',500,450)
                      break;
                  case 'batchHandler':
                      var data = checkStatus.data;
                      res = [];
                      if(data.length <= 0 ){
                          layer.msg('至少选择一项');
                          return false;
                      }
                      for(var i=0;i<data.length;i++){    //循环筛选出id
                          res.push(data[i].id);
                      }
                      layer.confirm('确定批量删除轮播图吗', function(index){
                          $.ajax({
                              url: 'bachDel',
                              type: 'post',
                              dataType: 'json',
                              data: {id:res},
                          }).done(function(data){
                              //回调提示
                              if(data.code==0){
                                  layer.msg(data.msg,{icon:2,time:1000});
                              }else{
                                  layer.msg(data.msg,{icon:1,time:1500},function(){
                                      parent.location.reload();
                                  });
                              }
                          })
                      })
                      break;
              }
          })
      })

  })
</script>
{/block}